package my.diplom.web.validators;

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.apache.log4j.Logger;
import my.diplom.entity.User;
import my.diplom.entity.Category;

/**
 * Created by IntelliJ IDEA.
 * User: GGobozov
 * Date: 02.08.2009
 * Time: 14:05:40
 * To change this template use File | Settings | File Templates.
 */
public class CreateCategoryValidator implements Validator {

    private static final Logger log = Logger.getLogger(CreateCategoryValidator.class);


    public boolean supports(Class clazz) {
        return Category.class.equals(clazz);
    }

    @Override
    public void validate(Object o, Errors errors) {
        log.debug("validate category" + o);
        Category category = (Category) o;
        if (category == null) errors.reject("Null data received");

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "categoryName", "categoryName.empty", "category Name is required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "status", "status.empty", "status is required");



    }
}
